{% extends "base.html" %}
{# Copyright The IETF Trust 2016-2024, All Rights Reserved #}
{% load origin django_bootstrap5 static person_filters textfilters %}
{% block title %}
    {% if revising_review %}
        Revise
    {% elif assignment %}
        Complete
    {% else %}
        Submit unsolicited
    {% endif %}
    review of {{ doc.name }}
{% endblock %}
{% block pagehead %}
    <link rel="stylesheet" href="{% static 'ietf/css/datepicker.css' %}">
{% endblock %}
{% block content %}
    {% origin %}
    <h1>
        {% if revising_review %}
            Revise
        {% elif assignment %}
            Complete
        {% else %}
            Submit unsolicited
        {% endif %}
        review
        <br>
        <small class="text-body-secondary">{{ doc.name }}</small>
    </h1>
    {% if assignment %}
        <table class="my-3 table table-sm table-borderless">
            <tbody>
                <tr>
                    <th scope="row">Review type:</th>
                    <td>{{ assignment.review_request.team.acronym }} - {{ assignment.review_request.type }} review</td>
                </tr>
                <tr>
                    <th scope="row">Requested version for review:</th>
                    <td>{{ assignment.review_request.requested_rev|default:"Current" }}</td>
                </tr>
                <tr>
                    <th scope="row">Requested:</th>
                    <td>{{ assignment.review_request.time|date:"Y-m-d" }}</td>
                </tr>
                <tr>
                    <th scope="row">Reviewer:</th>
                    <td>{% person_link assignment.reviewer.person %}</td>
                </tr>
            </tbody>
        </table>
    {% else %}
        <p class="alert alert-info my-3">
            You are submitting an <strong>unsolicited</strong> review for this document for the {{ team }}.
            <strong>This process should only be used for unsolicited reviews.</strong>
            A review request and assignment will be created automatically upon submitting this review.
        </p>
    {% endif %}
    {% if assignment and not revising_review %}
        <p>
            The review findings should be made available here and the review
            posted to the mailing list. If you enter the findings below, the
            system will post the review for you. If you already have posted
            the review, you can try to let the system find the link to the
            archive and retrieve the email body.
        </p>
        <p>
            If you enter the review below, the review will be sent
            to {% for addr in review_to %}{{ addr|linkify }}{% if not forloop.last %}, {% endif %}{% endfor %}{% if review_cc %}, with a CC to {% for addr in review_cc %}{{ addr|linkify }}{% if not forloop.last %}, {% endif %}{% endfor %}{% endif %}.
        </p>
    {% elif assignment %}
        <p>
            You can revise this review by entering the results below.
        </p>
    {% endif %}
    <form class="complete-review " method="post" enctype="multipart/form-data">
        {% csrf_token %}
        {% bootstrap_form form layout="horizontal" %}
        <button type="submit" class="btn btn-primary">
            {% if revising_review %}
                Revise
            {% else %}
                Complete
            {% endif %}
            review
        </button>
        {% if assignment %}
            <a class="btn btn-secondary float-end"
               href="{% url "ietf.doc.views_review.review_request" name=doc.name request_id=assignment.review_request.pk %}">
                Back
            </a>
        {% else %}
            <a class="btn btn-secondary float-end" href="{{ doc.get_absolute_url }}">Back</a>
        {% endif %}
        <div class="template d-none">
            {% if mail_archive_query_data %}
                <div class="mail-archive-search"
                    {% if assignment %}
                     data-search-mail-archive-url="{% url "ietf.doc.views_review.search_mail_archive" name=doc.name assignment_id=assignment.pk %}"
                    {% else %}
                     data-search-mail-archive-url="{% url "ietf.doc.views_review.search_mail_archive" name=doc.name acronym=team.acronym %}"
                    {% endif %}
                     data-is-reviewer="{{ is_reviewer|yesno:"true,false" }}">
                    <div class="offset-md-2 col-md-10">
                        <label for="mail-archive-subjects" class="form-label">Search {{team.list_email}} mail archive subjects for:</label>
                        <div class="input-group mb-3">
                            <input type="text" id="mail-archive-subjects"
                                   class="query-input form-control"
                                   value="{{ mail_archive_query_data.query_value }}">
                            <button type="button" class="search btn btn-primary">Search</button>
                        </div>
                        <div class="retrieving d-none my-3">
                            <div class="spinner-border spinner-border-sm" role="status"></div>
                            Searching...
                        </div>
                        <div class="results d-none my-3">
                            <p>
                                Select one of the following messages to automatically pre-fill link and content:
                            </p>
                            <div class="list-group"></div>
                        </div>
                        <div class="error alert alert-warning d-none my-3">
                            <span class="content">&nbsp;</span>
                            <span class="d-none try-yourself">
                                (searched for
                                <a class="query-url" href="#">"<span class="query">&nbsp;</span>"</a>,
                                corresponding
                                <a class="query-data-url" href="#">export</a>).
                            </span>
                            You have to fill in link and content yourself.
                        </div>
                    </div>
                </div>
            {% else %}
                <div class="mail-archive-search">
                    <small class="text-body-secondary">Mailing list does not have a recognized ietf.org archive. Auto-searching disabled.</small>
                </div>
            {% endif %}
        </div>
        {% spaceless %}
            <div class="template d-none">
                <button type="button" class="mail-archive-search-result list-group-item">
                    <small class="date float-end">&nbsp;</small>
                    <small class="from float-end">&nbsp;</small>
                    <span class="subject">&nbsp;</span>
                </button>
            </div>
        {% endspaceless %}
    </form>
{% endblock %}
{% block js %}
    <script src="{% static 'ietf/js/datepicker.js' %}"></script>
    <script src="{% static 'ietf/js/complete-review.js' %}"></script>
{% endblock %}